home *** CD-ROM | disk | FTP | other *** search
/ 220 Jogos / 220 jogos.iso / classicos / resta11 / SSnowflakes.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-12-22  |  2.7 KB  |  110 lines

  1. // SSnowflakes.cpp: Implementierung der Klasse SSnowflakes.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4.  
  5. #include "stdafx.h"
  6.  
  7. #include "SSnowflakes.h"
  8.  
  9. #ifdef _DEBUG
  10. #undef THIS_FILE
  11. static char THIS_FILE[]=__FILE__;
  12. #define new DEBUG_NEW
  13. #endif
  14.  
  15. #define MAX_X_VALUE 50
  16. #define MAX_Y_VALUE 25
  17. #define MAX_Z_VALUE 50
  18.  
  19. #define MIN_Y_VALUE -15.0f
  20.  
  21. //////////////////////////////////////////////////////////////////////
  22. // Konstruktion/Destruktion
  23. //////////////////////////////////////////////////////////////////////
  24.  
  25. SSnowflakes::SSnowflakes()
  26. {
  27.     snowFlakes = new SnowFlake[MAX_SNOWFLAKES];
  28. }
  29.  
  30. SSnowflakes::~SSnowflakes()
  31. {
  32.     delete[] snowFlakes;
  33. }
  34.  
  35. void SSnowflakes::create(STexture* tex)
  36. {
  37.     texture = tex;
  38.  
  39.     for (int i = 0; i < MAX_SNOWFLAKES; i += 1)
  40.     {
  41.         snowFlakes[i].position[0] = float(rand() % MAX_X_VALUE*10)/10.0f - float(rand() % MAX_X_VALUE*10)/10.0f;
  42.         snowFlakes[i].position[1] = float(rand() % MAX_Y_VALUE*10)/10.0f-2.0f;
  43.         snowFlakes[i].position[2] = -float(rand() % MAX_Z_VALUE*10)/10.0f;
  44.  
  45.         snowFlakes[i].rotation[0] = float(rand() % 360);
  46.         snowFlakes[i].rotation[1] = float(rand() % 360);
  47.         snowFlakes[i].rotation[2] = float(rand() % 360);
  48.  
  49.         snowFlakes[i].speed = float((rand() % 5) +1)/200;
  50.     }
  51.  
  52. }
  53.  
  54. void SSnowflakes::update(float frametime)
  55. {
  56.     glEnable(GL_BLEND);
  57.  
  58.     texture->select();
  59.  
  60.     for (int i = 0; i < MAX_SNOWFLAKES; i += 1)
  61.     {
  62.         SnowFlake& thisOne = snowFlakes[i];
  63.  
  64.         glPushMatrix();
  65.  
  66.         glTranslatef(thisOne.position[0],
  67.             thisOne.position[1],
  68.             thisOne.position[2]);
  69.  
  70.         /*glRotatef(1.0f,thisOne.rotation[0],thisOne.rotation[1],
  71.                         thisOne.rotation[2]);*/
  72.  
  73.         glRotatef(thisOne.rotation[0],1.0,0.0,0.0);
  74.         glRotatef(thisOne.rotation[1],0.0,1.0,0.0);
  75.         glRotatef(thisOne.rotation[2],0.0,0.0,1.0);
  76.  
  77.         
  78.         glBegin(GL_QUADS);
  79.             glColor3f(1.0,1.0,1.0);
  80.             glTexCoord2f(0.0,1.0); glVertex3f(-0.5,0.5,0.0);
  81.             glTexCoord2f(1.0,1.0); glVertex3f(0.5,0.5,0.0);
  82.             glTexCoord2f(1.0,0.0); glVertex3f(0.5,-0.5,0.0);
  83.             glTexCoord2f(0.0,0.0); glVertex3f(-0.5,-0.5,0.0);
  84.         glEnd();
  85.         
  86.         thisOne.position[1] -= thisOne.speed*frametime;
  87.  
  88.         thisOne.rotation[0] += 0.10f*frametime;
  89.         thisOne.rotation[1] += 0.10f*frametime;
  90.         thisOne.rotation[2] += 0.10f*frametime;
  91.  
  92.         if (thisOne.position[1] <= MIN_Y_VALUE)
  93.         {
  94.             thisOne.position[0] = float(rand() % MAX_X_VALUE*10)/10 - float(rand() % MAX_X_VALUE*10)/10;
  95.             thisOne.position[1] = MAX_Y_VALUE;
  96.             thisOne.position[2] = -float(rand() % MAX_Z_VALUE*10)/10;
  97.  
  98.             thisOne.rotation[0] = float(rand() % 360);
  99.             thisOne.rotation[1] = float(rand() % 360);
  100.             thisOne.rotation[2] = float(rand() % 360);
  101.  
  102.             thisOne.speed = float((rand() % 10) +1)/100.0f;
  103.         }
  104.  
  105.         glPopMatrix();
  106.     }
  107.  
  108.     glDisable(GL_BLEND);
  109. }
  110.